﻿@{
    WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "BANK PARTNER PROFILE";
    var pageMode=Page.Mode;
    if(pageMode==null){
        pageMode="0";
    }
    var bpp = Page.BankPartner;
    if(bpp==null){
        bpp = new BankPartner();
    }

    
}

<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 15em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>

<script>
     $(function(){
              //check page mode if, if mode 1 editModeOn, if 2 editModeOff
             if(@pageMode=='0'){
                saveModeOn();
             } 
             
             if(@pageMode=='1'){
                if(@bpp.Active=='1'){
                   $("select#bactive").find("option#Yes").attr("selected", true);
                    
                }else{
                  $("select#bactive").find("option#No").attr("selected", true);
                }
                editModeOn();
             }
            
            
              $("#action").click(function(){
                 var action = $(this).val();
                if(action=="SAVE"){
                    saveBPData();
                }else if(action=="EDIT"){
                    saveModeOn();
                }
               }); 
        
            $("#cancel").click(function(){
                editModeOn();
            });
    

   });

function saveBPData(){
     var data = $("#bp_data_form").serialize();
        $.post("/Maintenance/Services/RefDataService/bpsave",data,function(data){
            if(data[2]==null){
            var ccData = data[0];
        
           
            $("#message").empty();
            $("#bcode").val(ccData.Code);
            $("#bname").val(ccData.Name);
            $("#cardexp").val(ccData.CardExpiry);
            $("#cardlen").val(ccData.CardLength);
            $("#cardpre").val(ccData.CardPrefix);
            $("#authper").val(ccData.AuthContactPerson);
            $("#authemail").val(ccData.AuthEmail);
            $("#bactive").val(ccData.Active);

        
           // clearForm("#ccForm");
            //dialogCCSaveMode(createCashCard);
                 //$("#message").html("<p class='message error'>Bank Partner Profile has been saved</p>");
                 showMessage("Bank Partner Profile has been saved");                 
                }
                else{
                    //$("#message").html("<p class='message error'>Bank Partner Profile may have duplicates</p>");
                  showMessage("Bank Partner Profile may have duplicates");  
                }
    },"json");
    editModeOn();
}


function editModeOn(){
    $('#bpform :input').attr('disabled',true);
    $('#action').val("EDIT");
    $('#cancel').attr('disabled',true);
}


function saveModeOn(){
     $('#bpform :input').attr('disabled',false);
     $('#action').val("SAVE");
    $('#cancel').attr('disabled',false);
}

function showMessage(message){
    $('#message').html("<p class='message info'>"+message+"</p>");
    window.setTimeout(hideMessage,5000);
    
}

function hideMessage(){
    $("#message").empty();
}
</script>
<fieldset class="ui-widget ui-widget-content">
<div id="bpdiv"  method="post"  class="ui-widget" >
    <form id="bp_data_form">
    <div id="message" ></div>
    <input type="hidden" name="mode" id="mode" value="@pageMode"/>
    <input type="hidden" name="bpid" id="mode" value="@bpp.ID"/>
        
    <div id="bpform">    
        <p><label for="bcode">CODE </label><input type="text" name="bcode" id="bcode" value="@bpp.Code"/></p>
        <p><label for="bname">BANK NAME </label><input type="text" name="bname" id="bname" value="@bpp.Name"/></p>
        <p><label for="cardexp">CARD EXPIRY (months) </label><input type="text" name="cardexp" id="cardexp" value="@bpp.CardExpiry"/></p>
        <p><label for="cardlen">CARD LENGTH </label><input type="text" name="cardlen" id="cardlen" value="@bpp.CardLength"/></p>
        <p><label for="cardpre">CARD PREFIX </label><input type="text" name="cardpre" id="cardpre" value="@bpp.CardPrefix"/></p>
        <p><label for="authper">AUTHORIZED CONTACT PERSON </label><input type="text" name="authper" id="authper" value="@bpp.AuthContactPerson"/></p>
        <p><label for="authemail">AUTHORIZED EMAIL ADDRESS </label><input type="text" name="authemail" id="authemail" value="@bpp.AuthEmail"/></p>
        <p><label for="bactive">ACTIVE (Y/N) </label>
            <select name="bactive" id="bactive">
                
                <option id="Yes" value="1">Yes</option>
                <option id="No" value="0">No</option></select></p>
     </div>   
    <p><div id="buttons">
        <input type="button" value="SAVE" id="action"/>
        <input type="button" value="CANCEL" id="cancel"/></div></p>
        
    </form>
</div>
    </fieldset>